/* author : Sharat Achary 
*/

	var colors = ["#74A817", "#2FBEC4", "#F89520", "#EA0A86"],
		board = $("#countDownCanvas").get(0),
		ctx = board.getContext("2d"),
		xPos = 63,
		yPos = 70,
		radius = 55,
		startRadian = 1.5 * Math.PI,
		p0, p1, p2, p3,
		dayRef = $("#dayVal"),
		hrsRef = $("#hrsVal"),
		minRef = $("#minVal"),
		secRef = $("#secVal");
	
	ctx.lineWidth = 10;
		
	function prependZero(val){
		return (val < 10) ? "0"+val : ""+val; 
	}
	
	function getEndRadianFor(percent){
		return (percent * 2 * Math.PI) + 1.5 * Math.PI;
	};
	
	function clearBoard(){
		board.width = board.width;
	};
	
	function drawCountDownArc(day, hour, min, sec){
		p0 = day/365;
		p1 = hour/24;
		p2 = min/60;
		p3 = sec/60;
		
		dayRef.text(day);
		hrsRef.text(prependZero(hour));
		minRef.text(prependZero(min));
		secRef.text(prependZero(sec));
		
		clearBoard();
		ctx.lineWidth = 15;
		
		ctx.beginPath();		
		ctx.strokeStyle = colors[0];
		ctx.arc(xPos, yPos, radius, startRadian, getEndRadianFor(p0), false);
		ctx.stroke();
		
		ctx.beginPath();
		ctx.strokeStyle = colors[1];
		ctx.arc(xPos*3+15, yPos, radius, startRadian, getEndRadianFor(p1), false);
		ctx.stroke();
		
		ctx.beginPath();
		ctx.strokeStyle = colors[2];
		ctx.arc(xPos*5+40, yPos, radius, startRadian, getEndRadianFor(p2), false);
		ctx.stroke();
		
		ctx.beginPath();
		ctx.strokeStyle = colors[3];
		ctx.arc(xPos*7+58, yPos, radius, startRadian, getEndRadianFor(p3), false);
		ctx.stroke();
	}
	
	